package net.lzzy.entity;

import net.lzzy.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface CommentRepository extends JpaRepository<Comment,Integer> {



    @Query("SELECT c from t_comment c WHERE c.articleId = ?1")
    public List<Comment> selectCommentByArticleId(Integer id);

    @Query(value = "SELECT * FROM t_comment c WHERE c.a_id = ?1", nativeQuery = true)
    public List<Comment> selectCommentByArticleId2(Integer id);

    @Transactional
    @Modifying
    @Query(value = "INSERT INTO t_coment(author, content, a_id) values(?1,?2,?3)",nativeQuery = true)
    public  int addComment(String author, String content, Integer aId);
}
